/**
 *
 * 订单详情页所需处理的 业务逻辑
 *
 */
var  handler = {
    //客户取货
    pickup:function (obj,orderno,type,getway) {
        console.log('orderno=='+orderno);
        console.log('getway=='+getway);
        var val = $("input[name='confirmRefurbish']:checked").val();
        if(val=='001'){
            $.ajax({
                url:adminPath+'/order/pickup',
                type:'post',
                data:{type:type,orderno:orderno,getway:getway},
                success:function (data) {
                    if(data==1){
                        loading("确认操作成功" , 3);
                        $('#myModal').modal('hide');
                        window.location.href = window.location.href;
                    }
                }
            });
        } else{
            $('#myModal').modal('hide')
        }
    },
    //服务确认
    confirmService:function (obj,orderno,type,getway) {
        console.log('orderno=='+orderno);
        console.log('getway=='+getway);
        var val = $("input[name='confirmRefurbish']:checked").val();
        if(val=='001'){
            $.ajax({
                url:adminPath+'/order/confirmService',
                type:'post',
                data:{type:type,orderno:orderno,getway:getway},
                success:function (data) {
                    if(data==1){
                        loading("确认操作成功" , 3);
                        $('#myModal').modal('hide');
                        window.location.href = window.location.href;
                    }
                }
            });
        } else{
            $('#myModal').modal('hide')
        }
    },
    //商城退款申请处理
    confirmRefund:function (obj, orderno, type) {
        console.log('orderno=='+orderno);
        var val = $("input[name='confirmRefund']:checked").val();
        if(val=='001' || val=='002'){
            $.ajax({
                url:adminPath+'/order/confirmRefund',
                type:'post',
                data:{type:type,orderno:orderno,confirm:val},
                success:function (data) {
                    if(data==1){
                        loading("退款申请处理完毕" , 3);
                        $('#myModal').modal('hide');
                        window.location.href = window.location.href;
                    }
                }
            });
        } else{
            $('#myModal').modal('hide')
        }
    },

    confirmOK:function (obj,orderno,type) {
        $.tzConfirm({title:"友情提示",content:"订单确认已经完成了吗?",callback:function(ok){
            if(ok){
                var $this = $(obj);
                clearTimeout(this.timer);
                var params = {};
                params["orderno"] = orderno;
                params["type"] = type;
                this.timer = setTimeout(function(){
                    //alert(adminPath+"/"+model+"/delete");
                    loading("请稍后数据执行中...");
                    $.ajax({
                        type:"post",
                        url:adminPath+"/order/confirmOK",
                        data:params,
                        success:function(data){
                            if(data==1){
                                loading("执行成功...",3);
                                window.location.href = window.location.href;
                            }
                        }
                    });
                },200);
            }
        }});
    },
    //异步请求物流信息
    getExpress:function () {
        var logisticsno = $("#logisticsno").val();
        var logisticsnoComp = $("#logisticsnoComp").val();
        var userlogisticsno = $("#userlogisticsno").val();
        var userlogisticsComp = $("#userlogisticsnoComp").val();
        var params = {
            logisticsno:logisticsno,
            logisticsnocomp:logisticsnoComp ,
            userlogisticsno:userlogisticsno,
            userlogisticsnocomp:userlogisticsComp
        };
        console.log('params===' + JSON.stringify(params));
        if((isNotEmpty(logisticsno) && isNotEmpty(logisticsnoComp)) || (isNotEmpty(userlogisticsno) && isNotEmpty(userlogisticsComp))){
            $.ajax({
                url:adminPath + "/order/getOrderTracesByJson" ,
                type:'post',
                data:params,
                success:function (data) {
                    console.log('物流信息传进来来吗=='+JSON.stringify(data));
                    if(data){
                        if(data.userLogics){
                            var arr =data.userLogics.Traces;
                            if(arr){
                                var html = '';
                                for(var i=arr.length-1;i>0;i--){
                                    html +=  "<p>"+arr[i].AcceptTime+"  "+ arr[i].AcceptStation+"</p>"
                                }
                                $("#tab3 .paddingR20").html(html);
                            }
                        }
                        if(data.logics){
                            var arr =data.logics.Traces;
                            if(arr){
                                var html = '';
                                for(var i=arr.length-1;i>0;i--){
                                    html +=  "<p>"+arr[i].AcceptTime+"  "+ arr[i].AcceptStation+"</p>"
                                }
                                $("#tab4 .paddingR20").html(html);
                            }

                        }
                    }
                }
            });
        }
    },
    //定价
    confirmFix:function (obj , orderno , type,openid) {
        var price = $("#fixPrice").val();
         if(isEmpty(price)){
             loading("定价价格不能为空",3);
         }else if(price<0){
             loading("定价价格必须为正数",3);
         }else{
             $.ajax({
                 url:adminPath + "/order/fixPrice",
                 type:"post",
                 data:{orderno:orderno,type:type,aturalprice:price,openid:openid},
                 success:function (data) {
                    if(data == "success"){
                        loading("定价完成，价格为："+price+"元",3);
                        $('#myModal').modal('hide');
                        setTimeout(function () {
                            window.location.href = window.location.href;
                        },3);
                    }
                 }
             });
         }
    },
    //商城退款金额确认
    confirmRefundMoney:function(obj , orderno, type, userId, actualpayprice){
        var params = {orderno:orderno ,type:type ,userId:userId ,actualpayprice:actualpayprice};
        console.log(JSON.stringify(params));
        $.ajax({
            url:adminPath+"/order/confirmRefundMoney",
            type:"post",
            data:params,
            success:function (data) {
                console.log(JSON.stringify(data));
                if(data == "success"){
                    loading("退款成功",4);
                    setTimeout(function () {
                        $('#myModal').modal('hide');
                        window.location.href = window.location.href;
                    },6);

                }
            }
        });
    },
    //回收金额确认
    confirmRecycleMoney:function(obj , orderno, type, userId, totalprice){
        var params = {orderno:orderno ,type:type ,userId:userId ,totalprice:totalprice};
        console.log(JSON.stringify(params));
        $.ajax({
            url:adminPath+"/order/confirmRecycleMoney",
            type:"post",
            data:params,
            success:function (data) {
                console.log(JSON.stringify(data));
                if(data == "success"){
                    loading("回收金额确认成功",4);
                    setTimeout(function () {
                        $('#myModal').modal('hide');
                        window.location.href = window.location.href;
                    },6);

                }
            }
        });
    },

    //进入收货证明页面修改
    editReceiveTest:function (data) {
        window.location.href = adminPath + "/editReceiveTest/"+orderno+"/"+type;
    }

}